 
var tableManage = function() {

	var _init = function() {
        var table = $('#table_order');
        var tableUnit = table.dataTable({
            "processing": true,  // 开启服务器模式
            serverSide: true,
            "ajax": {
                url: index_list
            },
            "autoWidth": false,
            "columns": [
                {
                    "width": "12%",  //买家
                    "data": "nickName",
                    "render": function (data, type, row, meta) {
                        if (data) {
                            return data;
                        } else {
                            return "未绑定微信昵称";
                        }
                    }
                },
                {
                    "width": "12%",//手机号
                    "data": "mobile",
                    "render": function (data, type, row, meta) {
                        if (data) {
                            return data;
                        } else {
                            return "未绑定手机";
                        }
                    }
                },
                {
                    "width": "7%",
                    "data": "directShareNums",
                    "render": function (data, type, row, meta) {
                        if (data) {
                            return data;
                        } else {
                            return "0";
                        }
                    }
                },
                {
                    "width": "7%",
                    "data": "directShareQunNums",
                    "render": function (data, type, row, meta) {
                        if (data) {
                            return data;
                        } else {
                            return "0";
                        }
                    }
                },
                {
                    "width": "7%",
                    "data": "directBindNums",
                    "render": function (data, type, row, meta) {
                        if (data) {
                            return data;
                        } else {
                            return "0";
                        }
                    }
                },
                {
                    "width": "7%",
                    "data": "totalIncome",
                    "render": function (data, type, row, meta) {
                        return data / 100
                    }

                },
                {
                    "width": "7%",
                    "data": "totalWithdrawals",
                    "render": function (data, type, row, meta) {
                        return data / 100
                    }
                },
                {
                    "width": "15%",
                    "data": "null",
                    "defaultContent":
						'<button type="button" class="btn btn-info btn-xs btn_profit">收益</button>&nbsp;'+
						'<button type="button" class="btn bg-purple btn-xs btn_commission">提现</button>'
                }
            ],
            "language": {
                url: '/public/static/admin/pages/Chinese.json'
            },
            "pageLength": 10,
            "stateSave": true,
            "stateSaveParams": function (settings, data) {
                var search = data.search.search;
                if(search){
                    var arr = $.parseJSON(search);
                    for(var key in arr){
                        $("#searchForm input[name='"+key+"']").val(arr[key]);
                        $("#searchForm select[name='"+key+"']").val(arr[key]);
                    }
                }
            },
            "order": false,
            "columnDefs": [{
                "orderable": false,
                "targets": [0, 1, 2, 3, 4, 5, 6, 7]
            }],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
				"<t>" +
				"<'table_b relative'<'col-md-5'i><'col-md-7'>lp>",
            "fnInitComplete": function () {
            },
        });

        //用户动态查询
        $('#doQuery').click(function (event) {
            var search = $("#searchForm input[name='search']").val();
            var param = {"search": search};
            $('#table_order').DataTable().search(JSON.stringify(param)).draw();
        });

        // 查看收益明细
        table.on('click', '.btn_profit', function (event) {
            var oData_arr = table.DataTable().rows($(this).parents("tr")).data(); // 操作行对象
            var uperUserId = oData_arr[0].id;
            window.location.href = profit_url + "?userId=" + encodeURIComponent(uperUserId);

        });
        // 提现明细
        table.on('click', '.btn_commission', function (event) {
            var oData_arr = table.DataTable().rows($(this).parents("tr")).data(); // 操作行对象
            var uperUserId = oData_arr[0].id;
            window.location.href = commission_url + "?userId=" + encodeURIComponent(uperUserId);
        });
    };

	return {
		init: function() {
			_init();
		}
	};

}();

$(function() {
	tableManage.init();
});